//
//  MainViewController.swift
//  SinaWeibo
//
//  Created by 王佳琳 on 16/2/16.
//  Copyright © 2016年 王佳琳. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    @objc private func plusBtnDidClick() {
        print(__FUNCTION__)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        //打印对象的类型
        print(tabBar.classForCoder)
        let mainTabbar = MainTabbar()
        setValue(mainTabbar, forKey: "tabBar")
        let actionName = "plusBtnDidClick"
        //由于系统的tabbar是只读属性 不能够直接设置 可以通过kvc的方式在运行时 替换身份
        mainTabbar.plusBtn.addTarget(self, action: Selector(actionName), forControlEvents: .TouchUpInside)
        print(tabBar.classForCoder)
        //添加子视图控制器
        addChildViewControllers()
    }
    //添加多个视图
    private func addChildViewControllers() {
        addChildViewControllers(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewControllers(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewControllers(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewControllers(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }

   //添加单个视图
    private func addChildViewControllers(vc: UIViewController, title: String, imageName: String) {
        //设置渲染颜色
        tabBar.tintColor = UIColor.orangeColor()
        let nav = UINavigationController(rootViewController: vc)
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        addChildViewController(nav)
    }
}
